package com.xindacloud.sms.console.system.controller;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.xindacloud.sms.console.result.Result;
import com.xindacloud.sms.console.system.dto.SmsFriendshipLinkDTO;
import com.xindacloud.sms.console.system.entity.SmsFriendshipLink;
import com.xindacloud.sms.console.system.service.ISmsFriendshipLinkService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author czc
 * @since 2019-10-14
 */
@Api(tags = {"网站友情链接模块"})
@RestController
@RequestMapping("/api/v1/sms-friendship-link")
public class SmsFriendshipLinkController {
	
	@Autowired
	private ISmsFriendshipLinkService smsFriendshipLinkService;
	
	@ApiOperation(value = "查询友情链接列表",response=SmsFriendshipLink.class)
	@PostMapping(value = "/getSmsFriendshipLinkList")
	public Result getSmsFriendshipLinkList(@RequestBody SmsFriendshipLinkDTO smsFriendshipLinkDTO) {
	    return smsFriendshipLinkService.getSmsFriendshipLinkList(smsFriendshipLinkDTO);
	}
	
	@ApiOperation(value = "保存或修改友情链接")
	@PostMapping(value = "/saveOrUpdateSmsFriendshipLink")
	public Result saveOrUpdateSmsFriendshipLink(@RequestParam("file") MultipartFile file, HttpServletRequest req) {
		String name=req.getParameter("name");
		String linkAddress=req.getParameter("linkAddress");
		String icon=req.getParameter("icon");
		Integer openMethod=Integer.valueOf(req.getParameter("openMethod"));
		SmsFriendshipLinkDTO smsFriendshipLinkDTO=new SmsFriendshipLinkDTO();
		smsFriendshipLinkDTO.setName(name);
		smsFriendshipLinkDTO.setLinkAddress(linkAddress);
		smsFriendshipLinkDTO.setIcon(icon);
		smsFriendshipLinkDTO.setOpenMethod(openMethod);
		smsFriendshipLinkDTO.setState(0);
	    return smsFriendshipLinkService.saveOrUpdateSmsFriendshipLink(smsFriendshipLinkDTO);
	}
	
	@ApiOperation(value = "删除友情链接")
	@PostMapping(value = "/deleteSmsFriendshipLink")
	public Result deleteSmsFriendshipLink(@RequestBody SmsFriendshipLinkDTO smsFriendshipLinkDTO) {
	    return smsFriendshipLinkService.deleteSmsFriendshipLink(smsFriendshipLinkDTO);
	}
}
